// pages/feedback/feedback.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        UpLoadImgs:[],
        chooseImgs:[],
        textVal:'',
        tabs:[
            {
                id:0,
                value:"体验问题",
                isActive:true
            },
            {
                id:1,
                value:"商品，商家投诉",
                isActive:false
            }
        ],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
    handletabsItemChange(e){
        //1.获取被点击的索引
        const {index}=e.detail;
        let {tabs}=this.data;
        tabs.forEach((v,i) =>i===index?v.isActive=true:v.isActive=false);
        this.setData({
            tabs
        })
    },
    handlechooseImg(){
        wx.chooseImage({
            count: 9,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success :(res)=> {
              // tempFilePath可以作为img标签的src属性显示图片
            //   const tempFilePaths = res.tempFilePaths
            this.setData({
                chooseImgs:[...this.data.chooseImgs,...res.tempFilePaths]
            })
            }
          })
    },
    handleremoveImg(e){
        const {index}=e.currentTarget.dataset;
        let {chooseImgs}=this.data;
        chooseImgs.splice(index,1);
        this.setData({
            chooseImgs
        })
    },
    /* 文本域的输入事件 */
    handleTextInput(e){
        this.setData({
            textVal:e.detail.value
        })
    },
    /* 提交按钮点击事件 */
    handleFormsubmit(){
        const {textVal,chooseImgs}=this.data;
        if(!textVal.trim()){
            wx.showToast({
              title: '输入不合法',
              icon:"none",
              mask:true
            })
            return;
        }
       chooseImgs.forEach((v,i)=>{
        wx.uploadFile({
            url: 'https://images.ac.cn/Home/Index/UploadAction', //仅为示例，非真实的接口地址
            filePath: v,
            name: 'file',
            formData: {
            },
            success (res){
              console.log(res)
            }
          })
       })
    }
})